local M = {}

---! 添加好友事件
function M:change_todo_friend(userId,GoodFriendId,type)
    local result = self:get_todo_friend(userId, GoodFriendId)
    if result ~= false then
        local rpc = {}
        rpc.method = "change_task"
        rpc.from_user = userId
        rpc.to_user = GoodFriendId
        rpc.type = type
        rpc.id = result
        rpc.behavior = "update"
        local ok, data = THREAD_D:send("database_yield", rpc)
        return true
    else
        return false
    end
end

function M:get_todo_friend(userId,GoodFriendId)
    local rpc = {}
    rpc.behavior = "get"
    rpc.condition = string.format(" WHERE from_user='%s' and to_user='%s'", userId, GoodFriendId)
    rpc.method = "change_task"
    local ok, data = THREAD_D:send("database_yield", rpc)
    if #data > 0 then
        local id = 0
        for key,val in pairs(data) do
            id = val.id
        end
        return id
    else
        return false
    end
end

F_CHAR_FRIEND = M
